package com.yonyou.train.web;

import com.yonyou.train.ResultJson;
import com.yonyou.train.StatusCode;
import com.yonyou.train.model.Class;
import com.yonyou.train.model.Class_Student;
import com.yonyou.train.model.Class_Sub;
import com.yonyou.train.service.CoursePreviewService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value="/coursepreview")
public class CoursePreviewController {
    @Autowired
    private CoursePreviewService coursePreviewService;
    @RequestMapping(value ="/",method = RequestMethod.GET)
    public Object doQueryCourse(HttpServletRequest request){
        List list=coursePreviewService.queryCourse(request.getHeader("token"));
        return ResultJson.success(StatusCode.SUCCESS,"success",list);
    }

    @RequestMapping(value ="/addcourse",method = RequestMethod.POST)
    public Object doAddCourse(@RequestBody Map<String,Map>  map){
//        Map map =new HashMap();
//        map.put("id",course.getId());
//        map.put("class_id",course.getClass_id());
//        map.put("user_id",course.getUser_id());
        coursePreviewService.addCourse(map.get("param"));
        return ResultJson.success(StatusCode.SUCCESS,"success","课程报名成功");
    }

    //代人报名确认
//    @RequestMapping(value ="/confirm",method = RequestMethod.POST)
//    public Object doSubstitute(@RequestBody List<Class_Student> list,HttpServletRequest request){
//        for(Class_Student stu:list){
//            coursePreviewService.addCourse(stu,request.getHeader("token"));
//        }
//
//        return ResultJson.success(StatusCode.SUCCESS,"success","课程报名成功");
//    }
    @RequestMapping(value ="/users",method = RequestMethod.GET)
    public Object doFindUsers(@RequestParam String searchtext,HttpServletRequest request,@RequestParam long class_id){

        return ResultJson.success(StatusCode.SUCCESS,"success",coursePreviewService.dofindUsers(searchtext,request.getHeader("token"),class_id));
    }

    @RequestMapping(value ="/substitute",method = RequestMethod.GET)
    public Object dofindUsersByDept(HttpServletRequest request,@RequestParam long class_id){
        return ResultJson.success(StatusCode.SUCCESS,"success",coursePreviewService.findUsersByDept(request.getHeader("token"),class_id));

    }
}
